<html>
<head><meta charset="utf-8"><title>UnstableTransmuteFrom · project-safe-transmute · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/index.html">project-safe-transmute</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html">UnstableTransmuteFrom</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="217189643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217189643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217189643">(Nov 18 2020 at 20:07)</a>:</h4>
<p><span class="user-mention" data-user-id="125270">@scottmcm</span>, <span class="user-mention" data-user-id="239881">@Josh Triplett</span> </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">   </span><span class="n">Dst</span>: <span class="nc">UnstableTransmuteFrom</span><span class="o">&lt;</span><span class="n">Src</span><span class="p">,</span><span class="w"> </span><span class="n">Scope</span><span class="p">,</span><span class="w"> </span><span class="n">Options</span><span class="o">&gt;</span><span class="w"></span>
</code></pre></div>
<p>Where:</p>
<p>* <code>Src</code> is the source type<br>
  * <code>Dst</code> is the destination type<br>
  * <code>Scope</code> is a private type whose definition site is the reference point from which the visibility of <code>Src</code>'s and <code>Dst</code>'s fields is assessed.<br>
  * <code>Options</code> is a single or tuple combination of <code>TransmuteOptions</code></p>
<p>A <code>TransmuteOption</code> is one of the following void types:</p>
<p>* <code>NelectAlignment</code><br>
  * <code>NeglectValidity</code><br>
  * <code>NeglectVisibility</code> (bikeshed name?)</p>
<p>...or a tuple combination of the above (including the empty set of options <code>()</code>).</p>
<p>Each of these options corresponds to a static check to skip when checking the soundness and safety of a transmutation. The use of any of these options compromises the safety or well-definedness of a transmutation, but there are situations where <em>safer-but-not-safe</em> transmutation is exactly what you want:</p>
<ul>
<li><code>NeglectAlignment</code> is useful for crates like bytemuck.</li>
<li><code>NeglectValidity</code> is useful for building abstractions over falliable transmutations.</li>
<li><code>NeglectVisibility</code> is useful for building the <code>Muckable</code> system we've discussed where a different method is used to signal visibility.</li>
</ul>



<a name="217189837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217189837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217189837">(Nov 18 2020 at 20:09)</a>:</h4>
<p><span class="user-mention" data-user-id="219211">@Jack Wrenn</span> Two questions that raises...</p>



<a name="217189915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217189915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217189915">(Nov 18 2020 at 20:09)</a>:</h4>
<p>Is this <code>UnstableTransmuteFrom</code> (perma-unstable), or <code>UnsafeTransmuteFrom</code> (method is unsafe to invoke, albeit less unsafe than <code>std::mem::transmute</code>), or both?</p>



<a name="217190098"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217190098" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217190098">(Nov 18 2020 at 20:11)</a>:</h4>
<p>Second, is there any way we can avoid the concept of <code>Scope</code> entirely?</p>



<a name="217190210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217190210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217190210">(Nov 18 2020 at 20:11)</a>:</h4>
<p>This is <code>SemVerUnstableTransmuteFrom</code>.</p>
<p>It provides a fully-fledged analysis of well-definedness and safety, with the key shortcoming that it's <em>just</em> a compiler analysis and the compiler has no clue about SemVer stability. (Just as <code>mem::align_of</code> is just the compiler's analysis of a type's alignment, and doesn't care whether that alignment is semver stable.)</p>



<a name="217190282"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217190282" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217190282">(Nov 18 2020 at 20:12)</a>:</h4>
<p>I see. So naming aside, this is the trait that the compiler auto-generates and that you can't implement yourself?</p>



<a name="217190309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217190309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217190309">(Nov 18 2020 at 20:12)</a>:</h4>
<p>Bingo.</p>



<a name="217190320"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217190320" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217190320">(Nov 18 2020 at 20:12)</a>:</h4>
<p>OK, that makes sense.</p>



<a name="217190366"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217190366" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217190366">(Nov 18 2020 at 20:13)</a>:</h4>
<p>Then, <em>general</em> feedback: I'm in favor of separating the publicly visible trait (<code>TransmuteFrom</code>) from the compiler-generated trait, and writing the former in terms of the latter in <code>core</code>.</p>



<a name="217190514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217190514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217190514">(Nov 18 2020 at 20:14)</a>:</h4>
<p>I'm much less enthusiastic about some of the details of the compiler-generated trait, notably <code>Scope</code>. I'd love to hide that in some way that means we can arbitrarily change it without language/library stability guarantees.</p>



<a name="217190627"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217190627" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217190627">(Nov 18 2020 at 20:15)</a>:</h4>
<p>I also expect that we'll want to stabilize the public trait much sooner than we stabilize the compiler-generated trait.</p>



<a name="217190808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217190808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217190808">(Nov 18 2020 at 20:16)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217190098">said</a>:</p>
<blockquote>
<p>Second, is there any way we can avoid the concept of <code>Scope</code> entirely?</p>
</blockquote>
<p>No, not that we know of, unfortunately. The currently compiler <em>really</em> likes making the assumption that if <code>T: Trait</code> in one place, <code>T: Trait</code> in other places. If you want to make an implementation private today, you <em>need</em> to introduce a private type.</p>
<p>In the far-flung future, the compiler <em>might</em> get a sense of the provenance of trait bound requirements implicitly. If this occurs, <code>Scope</code> can perhaps be defaulted.</p>



<a name="217190902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217190902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217190902">(Nov 18 2020 at 20:17)</a>:</h4>
<p>It feels uncomfortable in particular to have <em>both</em> <code>Muckable</code> and <code>Scope</code>/<code>NeglectVisibility</code>.</p>



<a name="217191012"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217191012" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217191012">(Nov 18 2020 at 20:18)</a>:</h4>
<p>I think we have no choice but to have the separation given that we expect there to be an opt-in for this stuff.</p>
<p>I'd also be excited (assuming compiler is fine with it) to get some version of the internal trait implemented in nightly (if it isn't already) sooner rather than later, since that can always be changed.  And +1 to expecting the opt-in more-limited trait to stabilize well before the magic one -- I might even say that the magic one should never be stabilized, like an intrinsic, though perhaps some other core trait would expose it through a blanket impl or something at some point.</p>



<a name="217192609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217192609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217192609">(Nov 18 2020 at 20:31)</a>:</h4>
<p>(Returning to this topic for discussion on the <code>Scope</code> parameter.)</p>



<a name="217192774"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217192774" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217192774">(Nov 18 2020 at 20:32)</a>:</h4>
<p>Suppose we had a future version of Rust where you could have private trait impls, and the compiler pays attention to the invoking scope to determine if you're allowed to know that <code>T: Trait</code>.</p>



<a name="217192794"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217192794" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217192794">(Nov 18 2020 at 20:32)</a>:</h4>
<p>(I'm 100% on board that <code>TransmuteFrom</code> <strong>won't</strong> haven't a <code>Scope</code> parameter, btw.)</p>



<a name="217192817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217192817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217192817">(Nov 18 2020 at 20:33)</a>:</h4>
<p>...go on.</p>



<a name="217192876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217192876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217192876">(Nov 18 2020 at 20:33)</a>:</h4>
<p>What would <code>UnstableTransmuteFrom</code> look like then, and how can we design the current trait so that it's completely forward-compatible in all the details we might ever consider stabilizing?</p>



<a name="217193040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217193040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217193040">(Nov 18 2020 at 20:34)</a>:</h4>
<p>Given compiler support, could we <em>completely</em> hide the <code>Scope</code> parameter, so that you can't name it, can't turbofish it, can't pass it from one generic invocation to another (via <code>UnstableTransmuteFrom&lt;..., Scope, ...&gt;, ... Scope ...</code>)...</p>



<a name="217193105"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217193105" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217193105">(Nov 18 2020 at 20:35)</a>:</h4>
<p>Just make it an invisible implementation detail of how the compiler pseudo-implements having scope for impls in the first place?</p>



<a name="217193141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217193141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217193141">(Nov 18 2020 at 20:35)</a>:</h4>
<p>So that if we have "native" support for that kind of scoping and visibility, it goes away entirely without breaking anything (except <code>core</code> which can change to match)?</p>



<a name="217193280"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217193280" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217193280">(Nov 18 2020 at 20:36)</a>:</h4>
<p>I remember the macro approach, but I'm wondering if there's some way to just have the equivalent of <code>Scope=Here!()</code> (defaulting) without exposing either <code>Here!</code> or <code>Scope</code> to any user of <code>UnstableTransmuteFrom</code>.</p>



<a name="217193321"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217193321" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217193321">(Nov 18 2020 at 20:36)</a>:</h4>
<p>Having an explicit <code>Scope</code> parameter is essential for preserving type privacy across generic abstractions. If you can figure out how to correctly infer the right <code>Scope</code> parameter every time, you've figured out how to make private impls work generally.</p>



<a name="217193357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217193357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217193357">(Nov 18 2020 at 20:37)</a>:</h4>
<p>/me tries to process that.</p>



<a name="217193513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217193513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217193513">(Nov 18 2020 at 20:38)</a>:</h4>
<p>/me has to go to another meeting.</p>



<a name="217193523"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217193523" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217193523">(Nov 18 2020 at 20:38)</a>:</h4>
<p><span class="user-mention silent" data-user-id="219211">Jack Wrenn</span> <a href="#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217193321">said</a>:</p>
<blockquote>
<p>Having an explicit <code>Scope</code> parameter is essential for preserving type privacy across generic abstractions. If you can figure out how to correctly infer the right <code>Scope</code> parameter every time, you've figured out how to make private impls work generally.</p>
</blockquote>
<p>I'd like to understand this better, later.</p>



<a name="217193553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217193553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217193553">(Nov 18 2020 at 20:38)</a>:</h4>
<p>I feel like understanding this would be key to understanding how much "innate complexity" this has to have and how much we can reasonably contain.</p>



<a name="217193791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217193791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217193791">(Nov 18 2020 at 20:41)</a>:</h4>
<p><em>(This is the explanation from an earlier version of the RFC...)</em></p>
<p>This explicit <code>Scope</code> parameter of <code>TransmuteFrom</code> makes possible the creation of generic abstractions over it. For instance, consider a hypothetical <code>FromZeros</code> trait that indicates whether <code>Self</code> is safely initializable from a sufficiently large buffer of zero-initialized bytes:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">mod</span> <span class="nn">zerocopy</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">unsafe</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="n">FromZeros</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="sd">/// Safely initialize `Self` from zeroed bytes.</span>
<span class="w">        </span><span class="k">fn</span> <span class="nf">zeroed</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="cp">#[derive(Copy, Clone, PromiseTransmutableInto)]</span><span class="w"></span>
<span class="w">    </span><span class="cp">#[repr(u8)]</span><span class="w"></span>
<span class="w">    </span><span class="k">enum</span> <span class="nc">Zero</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">Zero</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="k">u8</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="k">unsafe</span><span class="w"> </span><span class="k">impl</span><span class="o">&lt;</span><span class="n">Dst</span><span class="o">&gt;</span><span class="w"> </span><span class="n">FromZeros</span><span class="o">&lt;</span><span class="n">Neglect</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Dst</span><span class="w"></span>
<span class="w">    </span><span class="k">where</span><span class="w"></span>
<span class="w">        </span><span class="n">Dst</span>: <span class="nc">TransmuteFrom</span><span class="o">&lt;</span><span class="p">[</span><span class="n">Zero</span><span class="p">;</span><span class="w"> </span><span class="kt">usize</span>::<span class="n">MAX</span><span class="p">],</span><span class="w"> </span><span class="o">???</span><span class="w"> </span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">fn</span> <span class="nf">zeroed</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="p">[</span><span class="n">Zero</span><span class="p">;</span><span class="w"> </span><span class="n">size_of</span>::<span class="o">&lt;</span><span class="bp">Self</span><span class="o">&gt;</span><span class="p">].</span><span class="n">transmute_into</span><span class="p">()</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>The above definition leaves ambiguous (<code>???</code>) the scope in which the constructability of <code>Dst</code> is checked: is it from the perspective of where this trait is defined, or where this trait is <em>used</em>? You probably do <em>not</em> intend for this trait to <em>only</em> be usable with <code>Dst</code> types that are defined in the same scope as the <code>FromZeros</code> trait!</p>
<p>Adding an explicit <code>Scope</code> parameter to <code>FromZeros</code> makes this unambiguous; the transmutability of <code>Dst</code> should be assessed from where the trait is used, <em>not</em> where it is defined:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">unsafe</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="n">FromZeros</span><span class="o">&lt;</span><span class="n">Scope</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="sd">/// Safely initialize `Self` from zeroed bytes.</span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">zeroed</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">unsafe</span><span class="w"> </span><span class="k">impl</span><span class="o">&lt;</span><span class="n">Dst</span><span class="p">,</span><span class="w"> </span><span class="n">Scope</span><span class="o">&gt;</span><span class="w"> </span><span class="n">FromZeros</span><span class="o">&lt;</span><span class="n">Scope</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Dst</span><span class="w"></span>
<span class="k">where</span><span class="w"></span>
<span class="w">    </span><span class="n">Dst</span>: <span class="nc">TransmuteFrom</span><span class="o">&lt;</span><span class="p">[</span><span class="n">Zero</span><span class="p">;</span><span class="w"> </span><span class="kt">usize</span>::<span class="n">MAX</span><span class="p">],</span><span class="w"> </span><span class="n">Scope</span><span class="o">&gt;</span><span class="w"></span>
<span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">zeroed</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="p">[</span><span class="n">Zero</span><span class="p">;</span><span class="w"> </span><span class="n">size_of</span>::<span class="o">&lt;</span><span class="bp">Self</span><span class="o">&gt;</span><span class="p">].</span><span class="n">transmute_into</span><span class="p">()</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>A third-party could then use <code>FromZeros</code> like so:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">use</span><span class="w"> </span><span class="n">zerocopy</span>::<span class="n">FromZeros</span><span class="p">;</span><span class="w"></span>

<span class="cp">#[derive(PromiseTransmutableInto)]</span><span class="w"></span>
<span class="cp">#[repr(C)]</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="o">..</span><span class="p">.</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="c1">// Initialize `Foo` from zero-initialized bytes.</span>
<span class="kd">let</span><span class="w"> </span><span class="n">_</span>: <span class="nc">Foo</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">FromZeros</span>::<span class="o">&lt;</span><span class="n">_</span><span class="p">,</span><span class="w"> </span><span class="n">Here</span><span class="o">!</span><span class="p">()</span><span class="o">&gt;</span>::<span class="n">zeroed</span><span class="p">();</span><span class="w"></span>
</code></pre></div>



<a name="217194220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217194220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217194220">(Nov 18 2020 at 20:45)</a>:</h4>
<p>Oh, huh, here's another thought, <span class="user-mention" data-user-id="239881">@Josh Triplett</span> (for whenever you return): If someday Rust gets <code>Scope</code> inference, than <code>UnstableTransmuteFrom</code> is mostly just a clunkier way of using <code>TransmuteFrom</code>, because <code>TransmuteFrom</code> can then gain those same constructability-aware superpowers.</p>



<a name="217203009"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217203009" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217203009">(Nov 18 2020 at 22:06)</a>:</h4>
<p><span class="user-mention silent" data-user-id="219211">Jack Wrenn</span> <a href="#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217194220">said</a>:</p>
<blockquote>
<p>Oh, huh, here's another thought, <span class="user-mention silent" data-user-id="239881">Josh Triplett</span> (for whenever you return): If someday Rust gets <code>Scope</code> inference, than <code>UnstableTransmuteFrom</code> is mostly just a clunkier way of using <code>TransmuteFrom</code>, because <code>TransmuteFrom</code> can then gain those same constructability-aware superpowers.</p>
</blockquote>
<p>Not quite. There's still some value in separating <code>Muckable</code> from the compiler-generated compatibility trait, and allowing people to implement other mechanisms on top of the compiler-generated trait (such as <code>TryTransmuteFrom</code>).</p>



<a name="217203130"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217203130" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217203130">(Nov 18 2020 at 22:07)</a>:</h4>
<p>Good point. Still, in that case, <code>UnstableTransmuteFrom</code> would just be a clunkier way of using <code>TryTransmuteFrom</code>, which would also presumably inherit scope-awareness.</p>



<a name="217432309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217432309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217432309">(Nov 20 2020 at 17:23)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> have you had a chance took look over <a href="#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217193791">this example</a>?</p>



<a name="217444289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217444289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217444289">(Nov 20 2020 at 19:00)</a>:</h4>
<p><span class="user-mention" data-user-id="219211">@Jack Wrenn</span> I did. I understand, now, why <code>Scope</code> has to be passed around explicitly. I don't, however, understand why the <em>caller</em> has to pass it in explicitly.</p>



<a name="217444360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217444360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217444360">(Nov 20 2020 at 19:01)</a>:</h4>
<p>Can we not teach the compiler to pass in <code>Here!()</code> implicitly, as a default?</p>



<a name="217444407"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217444407" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217444407">(Nov 20 2020 at 19:01)</a>:</h4>
<p>I would love for <code>Here!()</code> to be completely hidden and un-callable directly, if at all possible.</p>



<a name="217444727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217444727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217444727">(Nov 20 2020 at 19:04)</a>:</h4>
<p><code>Here!()</code> (or any private type—<code>Here!()</code> is just for convenience) would <em>not</em> be the right thing to fill in <code>???</code> with in this example:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">unsafe</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="n">FromZeros</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="sd">/// Safely initialize `Self` from zeroed bytes.</span>
<span class="w">        </span><span class="k">fn</span> <span class="nf">zeroed</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="cp">#[derive(Copy, Clone, PromiseTransmutableInto)]</span><span class="w"></span>
<span class="w">    </span><span class="cp">#[repr(u8)]</span><span class="w"></span>
<span class="w">    </span><span class="k">enum</span> <span class="nc">Zero</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">Zero</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="k">u8</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="k">unsafe</span><span class="w"> </span><span class="k">impl</span><span class="o">&lt;</span><span class="n">Dst</span><span class="o">&gt;</span><span class="w"> </span><span class="n">FromZeros</span><span class="o">&lt;</span><span class="n">Neglect</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">Dst</span><span class="w"></span>
<span class="w">    </span><span class="k">where</span><span class="w"></span>
<span class="w">        </span><span class="n">Dst</span>: <span class="nc">TransmuteFrom</span><span class="o">&lt;</span><span class="p">[</span><span class="n">Zero</span><span class="p">;</span><span class="w"> </span><span class="kt">usize</span>::<span class="n">MAX</span><span class="p">],</span><span class="w"> </span><span class="o">???</span><span class="w"> </span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">fn</span> <span class="nf">zeroed</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="p">[</span><span class="n">Zero</span><span class="p">;</span><span class="w"> </span><span class="n">size_of</span>::<span class="o">&lt;</span><span class="bp">Self</span><span class="o">&gt;</span><span class="p">].</span><span class="n">transmute_into</span><span class="p">()</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>...because that would denote "evaluate the constructability of <code>Dst</code> from the context of the <code>zerocopy</code> crate—where the concrete <code>Dst</code> type almost certainly isn't even reachable.</p>



<a name="217444833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217444833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217444833">(Nov 20 2020 at 19:05)</a>:</h4>
<p>I'm not suggesting you can't provide a <em>different</em> value, by passing in your own Scope type parameter.</p>



<a name="217444866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217444866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217444866">(Nov 20 2020 at 19:05)</a>:</h4>
<p>I understand that Scope can't be completely hidden; your example above made that clear.</p>



<a name="217444877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217444877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217444877">(Nov 20 2020 at 19:05)</a>:</h4>
<p>Gotcha!</p>



<a name="217444902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217444902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217444902">(Nov 20 2020 at 19:05)</a>:</h4>
<p>I'm asking if <code>Here!()</code> can be completely hidden and handled by the compiler if you don't pass in a Scope.</p>



<a name="217445010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217445010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217445010">(Nov 20 2020 at 19:06)</a>:</h4>
<p>Both for simplicity and for forward-compatibility with some future implementation with a different trait model.</p>



<a name="217445029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217445029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217445029">(Nov 20 2020 at 19:06)</a>:</h4>
<p>The less public surface area, the more we can evolve.</p>



<a name="217445214"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217445214" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217445214">(Nov 20 2020 at 19:08)</a>:</h4>
<p>I think that might be possible, but I can see it having a <em>lot</em> of tricky edge cases—just as default type parameters <em>already</em> have tricky, longstanding edge cases. I'd hate to add to that complexity.</p>



<a name="217445523"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217445523" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217445523">(Nov 20 2020 at 19:10)</a>:</h4>
<p>That's fair. I feel like it's worth attempting, and if we run into difficulties we can always consider alternatives.</p>



<a name="217445563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217445563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217445563">(Nov 20 2020 at 19:11)</a>:</h4>
<p><code>Here!()</code> was the biggest concern with the previous version, and I'm trying to figure out how we can avoid that and simplify.</p>



<a name="217445660"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217445660" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217445660">(Nov 20 2020 at 19:12)</a>:</h4>
<p>Hmmm. That does mean that we'll need some (eventually stable) way to denote a parameter that will default to the compiler-provided scope.</p>



<a name="217445749"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217445749" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217445749">(Nov 20 2020 at 19:12)</a>:</h4>
<p>Since the type parameter to <code>FromZeros</code> should default to that as well. Or any other Scope parameter for someone's trait built atop TransmuteFrom directly or indirectly.</p>



<a name="217446636"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217446636" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217446636">(Nov 20 2020 at 19:18)</a>:</h4>
<p>So: We're on the same page that there <em>are</em> cases where the explicit <code>Scope</code> parameter is necessary as it would be inappropriate to infer <code>Here!()</code>. If you're building generic abstractions over transmutation, it's inescapable that you'll have to think about <code>Scope</code>. (In fact, the cases where you leave it to be inferred probably are a mistake.)</p>
<p>For end-users <em>using</em> those abstractions on concrete types, it'd be nice if they <em>didn't</em> have to think about it. The RFC proposed achieving this with this macro:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="kr">macro</span><span class="w"> </span><span class="n">transmute</span><span class="p">(</span><span class="cp">$expr</span>: <span class="nc">expr</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">TransmuteFrom</span>::<span class="o">&lt;</span><span class="n">_</span><span class="p">,</span><span class="w"> </span><span class="n">Here</span><span class="o">!</span><span class="p">()</span><span class="o">&gt;</span>::<span class="n">transmute_from</span><span class="p">(</span><span class="cp">$expr</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="c1">//              ┯  ━━━┯━━━</span>
<span class="w">    </span><span class="c1">//              │     ┕ check constructability from `transmute!`'s invocation scope</span>
<span class="w">    </span><span class="c1">//              ┕ the destination type of the transmute (`_` used to infer the type from context)</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>This macro means that end-users don't necessarily even need to think about the trait <code>TransmuteFrom</code> at all, either.</p>
<p><code>Here!()</code> was just there for ergonomics. If it's a sticking point in its own right, the good news is that it's not actually needed at all. The technical goals of the <code>Scope</code> parameter require that it's just instantiated with a private type. It doesn't need to be a <em>particular</em> private type. So that macro could, equivalently, be written as:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="kr">macro</span><span class="w"> </span><span class="n">transmute</span><span class="p">(</span><span class="cp">$expr</span>: <span class="nc">expr</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">enum</span> <span class="nc">Here</span><span class="w"> </span><span class="p">{}</span><span class="w"> </span><span class="c1">// define a private type to represent `transmute!`'s invocation scope</span>
<span class="w">    </span><span class="n">TransmuteFrom</span>::<span class="o">&lt;</span><span class="n">_</span><span class="p">,</span><span class="w"> </span><span class="n">Here</span><span class="o">&gt;</span>::<span class="n">transmute_from</span><span class="p">(</span><span class="cp">$expr</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="c1">//              ┯  ━┯━━</span>
<span class="w">    </span><span class="c1">//              │   ┕ check constructability from visibility reference frame of `Here`</span>
<span class="w">    </span><span class="c1">//              ┕ the destination type of the transmute (`_` used to infer the type from context)</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="217450833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217450833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217450833">(Nov 20 2020 at 19:53)</a>:</h4>
<p>I think I should come at this from a different angle:</p>



<a name="217450953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217450953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217450953">(Nov 20 2020 at 19:54)</a>:</h4>
<p>I'm hoping it's possible for us to change the compiler, to add specific support for this kind of type parameter, and desugar it accordingly.</p>



<a name="217451075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217451075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217451075">(Nov 20 2020 at 19:55)</a>:</h4>
<p>Could we arrange to write this without a macro, and just let people write <code>TransmuteFrom::transmute_from</code>, with the compiler going "oh, there's a <code>Scope</code> parameter there, I should fill that in"?</p>



<a name="217451404"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217451404" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217451404">(Nov 20 2020 at 19:57)</a>:</h4>
<p>By way of non-ergonomic but plausible syntax: <code>trait FromZeroes&lt;#[scope_param] Scope&gt;</code>.</p>



<a name="217451686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217451686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217451686">(Nov 20 2020 at 19:59)</a>:</h4>
<p>That seems like an excellent basis for a <code>priv impl</code> RFC!</p>



<a name="217451973"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217451973" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217451973">(Nov 20 2020 at 20:01)</a>:</h4>
<p>Private impl seems related, in that it solves the same problem in a more fundamental way. This would be an intermediate step that's more feasible than fully scope-and-visibility-aware impls.</p>



<a name="217452046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217452046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217452046">(Nov 20 2020 at 20:01)</a>:</h4>
<p>I just don't want us to end up with a public surface area that <em>prevents</em> us from getting to either of those two points in the future.</p>



<a name="217452137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217452137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217452137">(Nov 20 2020 at 20:02)</a>:</h4>
<p>Also, to answer your earlier point, using a private type rather than a <code>Here!()</code> macro seems likely to be an improvement, yes. Makes the proposal seem like it has less magic in it. :)</p>



<a name="217454932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217454932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217454932">(Nov 20 2020 at 20:28)</a>:</h4>
<p>What's your motivation for wanting to make <code>Scope</code> implicit in some cases? Is it just ergonomics?</p>



<a name="217455644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217455644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217455644">(Nov 20 2020 at 20:35)</a>:</h4>
<p>Partly ergonomics, partly the thought that the "pass a type to indicate scope" mechanism may not be how we want to handle it in the future if the compiler gets smarter about scope, and I'd like that to not be part of the stable interface.</p>



<a name="217455677"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217455677" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217455677">(Nov 20 2020 at 20:35)</a>:</h4>
<p>Trying to minimize public surface area, in addition to wanting the interface to not require calling a macro.</p>



<a name="217455740"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217455740" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217455740">(Nov 20 2020 at 20:36)</a>:</h4>
<p>I'd like people to be able to treat <code>TransmuteFrom</code> as a normal trait most of the time, in terms of calling its functions.</p>



<a name="217455763"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217455763" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217455763">(Nov 20 2020 at 20:36)</a>:</h4>
<p>And not think about Scope unless they're building an interface atop it.</p>



<a name="217455894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217455894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217455894">(Nov 20 2020 at 20:37)</a>:</h4>
<p>What happens here?<br>
crate1:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">UnrelatedType</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">_private</span>: <span class="p">(),</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="cp">#[repr(transparent)]</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">Even</span><span class="p">(</span><span class="kt">u32</span><span class="p">);</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">Even</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">new</span><span class="p">(</span><span class="n">v</span>: <span class="kt">u32</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">assert_eq</span><span class="o">!</span><span class="p">(</span><span class="n">v</span><span class="w"> </span><span class="o">%</span><span class="w"> </span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">);</span><span class="w"></span>
<span class="w">        </span><span class="bp">Self</span><span class="p">(</span><span class="n">v</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>crate2:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">make_odd</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">crate1</span>::<span class="n">Even</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">TransmuteFrom</span>::<span class="o">&lt;</span><span class="n">_</span><span class="p">,</span><span class="w"> </span><span class="n">crate1</span>::<span class="n">UnrelatedType</span><span class="o">&gt;</span>::<span class="n">transmute_from</span><span class="p">(</span><span class="mi">1</span><span class="k">u32</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="217456036"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217456036" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217456036">(Nov 20 2020 at 20:39)</a>:</h4>
<p>No implementation found for yada yada yada. <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span> </p>
<p>The <code>Scope</code> parameter can only be instantiated with private types.</p>



<a name="217456150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217456150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217456150">(Nov 20 2020 at 20:40)</a>:</h4>
<p>Is there any way those types could "leak" via private-in-public?</p>



<a name="217456328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217456328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217456328">(Nov 20 2020 at 20:42)</a>:</h4>
<p>My understanding is that the type privacy mechanism does a reachability-basis visibility analysis at implementation use-sites, and that these checks are relied upon to be air-tight. There's a bunch of conversation in the 'Type Privacy &amp; Safety' topic about this.</p>



<a name="217456395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217456395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217456395">(Nov 20 2020 at 20:43)</a>:</h4>
<p>crate1:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">struct</span> <span class="nc">UnrelatedType</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="k">struct</span> <span class="nc">PrivateType</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">func</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">UnrelatedType</span><span class="o">&lt;</span><span class="n">PrivateType</span><span class="o">&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">}</span><span class="w"></span>
<span class="c1">// plus `Even` from above</span>
</code></pre></div>
<p>crate2:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">make_odd</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">_unused</span>: <span class="nc">crate1</span>::<span class="n">UnrelatedType</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">crate1</span>::<span class="n">Even</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">TransmuteFrom</span>::<span class="o">&lt;</span><span class="n">_</span><span class="p">,</span><span class="w"> </span><span class="n">T</span><span class="o">&gt;</span>::<span class="n">transmute_from</span><span class="p">(</span><span class="mi">1</span><span class="k">u32</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="217456416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217456416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217456416">(Nov 20 2020 at 20:43)</a>:</h4>
<p>Try it. :)</p>



<a name="217456575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217456575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217456575">(Nov 20 2020 at 20:45)</a>:</h4>
<p>IIRC, you'll get two errors. First, a purely local priv-in-pub lint at the <code>func</code> definition site. Then, a hard, reachability-based error in <code>crate2</code>.</p>



<a name="217456668"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217456668" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217456668">(Nov 20 2020 at 20:46)</a>:</h4>
<p>I knew about the former, but not the latter.</p>



<a name="217456803"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217456803" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217456803">(Nov 20 2020 at 20:47)</a>:</h4>
<p>Does that still apply if you make <code>func()</code> return an <code>UnrelatedType&lt;impl SomeTrait&gt;</code> where <code>func()</code> gets to determine the type but not tell you about it?</p>



<a name="217456811"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217456811" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217456811">(Nov 20 2020 at 20:47)</a>:</h4>
<p>(trying that now)</p>



<a name="217457026"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217457026" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217457026">(Nov 20 2020 at 20:50)</a>:</h4>
<p>There are exceptions carved out for <em>anonymized</em> private types so it should let you "leak" it. However, you won't be able to snag implementations of <code>TransmuteFrom</code> in <code>crate2</code> using it, IIRC.</p>



<a name="217457102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217457102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217457102">(Nov 20 2020 at 20:50)</a>:</h4>
<p>So you might be able to get around the private-in-public issue, but not the reachability check in crate2?</p>



<a name="217457167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217457167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217457167">(Nov 20 2020 at 20:51)</a>:</h4>
<p>Yep. That was the conclusion of the discussion over on 'Type Privacy &amp; Safety'.</p>



<a name="217458309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217458309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217458309">(Nov 20 2020 at 21:03)</a>:</h4>
<p><span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span></p>



<a name="217458355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217458355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217458355">(Nov 20 2020 at 21:03)</a>:</h4>
<p>That definitely addresses one of my concerns about whether we'd find a soundness issue down the road.</p>



<a name="217459151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217459151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217459151">(Nov 20 2020 at 21:10)</a>:</h4>
<p>Glad to hear it. If there are issues with type privacy, the issues will be felt more broadly than <em>just</em> transmutation. <a href="#narrow/stream/216762-project-safe-transmute/topic/Type.20Privacy.20.26.20Safety/near/216805918">Some aspects of linking depend on type privacy</a>, and it wouldn't be unambiguously sound to implement a public traits for private types.</p>



<a name="217829314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217829314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jack Wrenn <a href="https://rust-lang.github.io/zulip_archive/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom.html#217829314">(Nov 24 2020 at 23:51)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/216762-project-safe-transmute/topic/UnstableTransmuteFrom/near/217455644">said</a>:</p>
<blockquote>
<p>Partly ergonomics, partly the thought that the "pass a type to indicate scope" mechanism may not be how we want to handle it in the future if the compiler gets smarter about scope, and I'd like that to not be part of the stable interface.</p>
</blockquote>
<p>If <code>UnstableTransmuteFrom</code> gains scope-inference powers in the future, we can non-breakingly surface that capability by defaulting the <code>Scope</code> parameter to some sigil signifying "scope inference me!" (e.g., <code>!</code> or <code>()</code>). Existing code that explicitly passes a <code>Scope</code> parameter will continue to work. New code can then either be in the form <code>Dst: UnstableTransmuteFrom&lt;Src&gt;</code>, or (if <code>Neglect</code> options need to be passed) <code>Dst: UnstableTransmuteFrom&lt;Src, !, Neglect&gt;</code>.</p>
<p>And, since <code>UnstableTransmuteFrom</code> is straight compiler magic anyways, we can take this one step further and treat <code>Dst: UnstableTransmuteFrom&lt;Src, Neglect&gt;</code> as <code>Dst: UnstableTransmuteFrom&lt;Src, !, Neglect&gt;</code>. (I think you proposed something like this in an earlier comment.)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>